function ListNode(val) {
  this.val = val;
  this.next = null;
}
var addTwoNumbers = function (l1, l2) {
  let result = new ListNode(null)
  let nextNode = result
  let param = 0
  while (l1 || l2) {
    let x = l1 ? l1.val : 0
    let y = l2 ? l2.val : 0
    let sum = Number(x) + Number(y) + param
    if (sum >= 10) {
      param = 1
      sum -= 10
    } else {
      param = 0
    }
    nextNode.next = new ListNode(sum)
    nextNode = nextNode.next
    l1 = l1 && l1.next ? l1.next : null
    l2 = l2 && l2.next ? l2.next : null
  }
  // 第一个数字大于10  进位
  if (param) {
    nextNode.next = new ListNode(param)
  }
  return result.next
};
(function () {
  let l1 = new ListNode('2')
  let next1 = l1
  let l2 = new ListNode('5')
  let next2 = l2
  let index = 1
  let arr1 = [2, 4, 3]
  let arr2 = [5, 6, 4]
  while (index < arr1.length) {
    next1.next = new ListNode(arr1[index])
    next2.next = new ListNode(arr2[index])
    next1 = next1.next
    next2 = next2.next
    index++
  }
  console.log(addTwoNumbers(l1, l2))
})()